home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / figplace.tex < prev    next >
Text File  |  1989-12-20  |  7KB  |  198 lines

  1. %
  2. %Date: Tue, 25 Oct 88 14:11:06 +0100
  3. %From: Joost Zalmstra <mcvax!nat.vu.nl!jjaz@uunet.UU.NET>
  4. %Subject: Re:Page Make-up Challenge
  5. %
  6. %Maybe the following set of macros can contribute to the solution of
  7. %the problem posed by David Rogers in TeXhax #86. It implements a floating
  8. %insertion with the following properties:
  9. % - Every insertion must be put in a \vbox. Customised macros can then
  10. %   be used to place the white space for the figure and the figure caption
  11. %   in this box.
  12. % - The order in which these \vbox-es are inserted is maintained.
  13. % - No more than two boxes are placed on one page: the first on the top
  14. %   and the second on the bottom of the page.
  15. %
  16. %The proposed macro \figplace should create a \vbox with the correct layout
  17. %of the figure and then call \addfigure to put it in the insertionlist:
  18. %
  19. %\def\figplace#1#2#3#4{setbox0=\vbox{%
  20. %% here call macros to place figure and caption
  21. %}
  22. %\addfigure0}
  23. %
  24. %Note that the space separating the figure from the text should not
  25. %be included in the \vbox. The skipregister \figureskip is used for this
  26. %purpose.
  27. %
  28. %The macros are written in plain TeX, in fact the output routine given
  29. %here is an extension of the plain output routine (TeX-book page 364).
  30. %
  31. %The basic idea is that figures that won't fit on the current page
  32. %are kept on a list (the \box \figlist). This list is checked after
  33. %a \shipout and if not empty a maximum of two \vboxes is inserted
  34. %(using plains \topins) for the next page. As the insertions are \vboxes
  35. %it is easy to split the insertion and put one at the top and one at
  36. %the bottom of the page.
  37. %
  38. %Two further refinements should be mentioned here.
  39. %1) If the figures on a page take so much room that less than a specified
  40. %amount of space (given in dimen register \minpagesize) is left for
  41. %the text, this text is shifted through to the next page.
  42. %2) By inserting a \vbox with height \vsize (created by \vbox to \vsize..)
  43. %a page insert is created. No extra \figureskip will be include in this case.
  44. %
  45. %I have tested these macros with real input (16 pages with on the first
  46. %page the insertion of several figures) and it seems to work on the moment.
  47. %However, I'm not a TeX guru and I would expect that these macros can be
  48. %improved. One of the problems left is te fact that \addfigures must
  49. %be called in horizontal mode ( \vadjust won't work). I would therefore
  50. %apreciate comments, both on the macros as they stand and on how this
  51. %contributes to the Challenge.
  52. %
  53. %Joost Zalmstra.
  54. %
  55. %jjaz%nat.vu.nl@hearn.bitnet
  56. \newbox\figlist
  57. \newcount\figuresonpage  \figuresonpage=0
  58. \newcount\figuresonlist  \figuresonlist=0
  59. \newskip\figureskip      \figureskip=1.2 pc plus 1 pc
  60. \newdimen\pagesize
  61. \newdimen\minpagesize    \minpagesize=5 pc
  62. \newdimen\figuresizeonpage
  63.  
  64. \def\addfigure#1{%    add figure in box #1 to the document
  65.     \ifnum\figuresonpage>1    % allready two figures on this page
  66.     \addtolist{#1}%        % so save for later
  67.     \else
  68.     \ifnum\figuresonlist>0    % figlist is not empty
  69.         \addtolist{#1}    % so save for later
  70.     \else            % no figures left over, so try to fit this one
  71.         \dimen0=\ht#1
  72.         \ifdim\dimen0<\vsize% not a pagesize figure
  73.            \advance\dimen0 by \dp#1   % size of the box
  74.            \advance\dimen0 by \figureskip  % extra space below or above
  75.         \fi
  76.         \advance\dimen0 by \pagetotal
  77.         \ifdim\dimen0>\pagegoal  % no space on this page
  78.         \addtolist{#1}         % so save for later
  79.         \else 
  80.         \advance\dimen0 by \figuresizeonpage
  81.         \ifdim\dimen0>\dimen\topins % exceding maximum insertion size
  82.             \addtolist{#1}          % so save for later
  83.         \else
  84.             \figureinsert{#1}          % insert the figure
  85.         \fi
  86.         \fi
  87.     \fi
  88.     \fi
  89. }
  90.  
  91. \def\addtolist#1{%    add box #1 to figlist
  92.     \global\setbox\figlist=\vbox{%
  93.     \nointerlineskip
  94.     \box#1
  95.     \unvbox\figlist}
  96.     \global\advance\figuresonlist by 1
  97. }
  98.  
  99. \def\figureinsert#1{%    insert figure on this page
  100.     \ifdim\ht#1<\vsize
  101.         \insert\topins{\vbox{%
  102.         \ifnum\figuresonpage=0
  103.             \unvbox#1\vskip\figureskip    % skip below the figure
  104.         \else
  105.             \vskip\figureskip\unvbox#1    % skip above the figure
  106.         \fi
  107.     }}
  108.     \else
  109.         \pageinsert
  110.         \unvbox#1
  111.     \endinsert
  112.     \fi
  113.     \global\advance\figuresonpage by 1
  114.     \global\advance\figuresizeonpage by \ht#1
  115.     \global\advance\figuresizeonpage by \dp#1
  116.     \global\advance\figuresizeonpage by \figureskip
  117. }
  118. \def\checkfiglist{%    see if there is a figure in the list that will
  119.           % fit on the next page
  120.     \ifnum\figuresonlist>0
  121.         \global\setbox\figlist=\vbox{%
  122.         \unvbox\figlist
  123.         \setbox0=\lastbox
  124.         \global\advance\dimen0\ht0
  125.         \ifdim\ht0<\vsize
  126.             \global\advance\dimen0 by \dp0
  127.             \global\advance\dimen0 by \figureskip
  128.         \fi
  129.         \ifdim\dimen0>\vsize
  130.              \vbox{\box0}    % no room ; replace the figure
  131.         \else
  132.             \ifdim\dimen0>\dimen\topins
  133.                   \vbox{\box0}
  134.           \else
  135.                 \global\advance\figuresonlist by -1
  136.             \fi
  137.         \fi
  138.         \global\setbox0=\box0
  139.     }
  140.     \else
  141.     {\setbox1=\box0        % make box0 void
  142.     \global\setbox0=\box0}
  143.     \fi
  144. }
  145. % Borrowing the macros from plain TeX
  146.  
  147. \catcode`@=11
  148. \output{\myoutput}
  149. \def\myoutput{\shipout\vbox{\makeheadline\pagebody\makefootline}%
  150.   \advancepageno
  151.   \global\figuresonpage=0
  152.   \dimen0=0pt
  153.   \global\figuresizeonpage = 0pt
  154.   \checkfiglist     % check if there is figure waiting and return it in box 0 
  155.   \ifvoid0          % nothing left
  156.   \else
  157.       \figureinsert0% insert this figure
  158.       \checkfiglist % check for a second figure
  159.       \ifvoid0\else
  160.           \figureinsert0
  161.        \fi
  162.   \fi
  163.   \ifvoid255\else\unvbox255\penalty\outputpenalty\fi % unused page back on list
  164.   \ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
  165.  
  166. \def\pagecontents{%
  167.     \ifnum\figuresonpage>0      % check for insertion of figures
  168.     \unvbox\topins    % place the figure(s) on top
  169.     \ifnum\figuresonpage=2
  170.         \setbox0=\lastbox   % remove the second figure
  171.     \fi
  172.     \setbox1=\lastbox
  173.     \unvbox1
  174.     \fi
  175. % Check box 255
  176.      \pagesize=\ht255
  177.      \advance\pagesize by \dp255       % determine size of box 255
  178.      \ifdim\pagesize>\minpagesize
  179.          \dimen@=\dp255 \unvbox255  % the real page contents
  180.      \else
  181.     \message{tekstsize = \the\ht255, \the\dp255}
  182.     \ifdim\ht255=0pt            % box is empty
  183.     \else
  184.        \vfil                      % to small so leave for next page
  185.     \fi
  186.      \fi
  187.     \ifnum\figuresonpage=2
  188.     \box0        % the second figure
  189.     \fi
  190.     \ifvoid\footins\else % footnote info is present
  191.       \vskip\skip\footins
  192.       \footnoterule
  193.       \unvbox\footins\fi
  194.     \ifr@ggedbottom \kern-\dimen@ \vfil \fi}
  195.  
  196. \catcode`@=12    % at signs no longer letters
  197.